package LeetCodeHot100TopInterview;

import java.util.Locale;

public class Q125_IsPalindrome {


    //验证回文
    public boolean isPalindrome(String s) {

        if (s == null || s.length() == 0){
            return true;
        }
        //去空格
        s = s.trim().replace(" ", "").replace(",", "").toLowerCase();
        //填充#
        char[] str = s.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length; i++) {
            if (Character.isLetterOrDigit(str[i])){
                sb.append(str[i]);
            }
        }
        str = sb.toString().toCharArray();
        //双指针
        int left = 0;
        int right = sb.length() - 1;
        while (left <= right){
            if (str[left++] != str[right--]){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Q125_IsPalindrome fun = new Q125_IsPalindrome();
        System.out.println(fun.isPalindrome("A man, a plan, a canal: Panama"));
    }
}
